<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="../datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/app.css">
    <link rel="stylesheet" type="text/css" href="../css/index.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="/h5/js/all.js"></script>

</head>
<style>
.companyPageActive{
    background-color: #3B7DF2 ! important;
    color: #fff ! important;
}
.nullCetner{
    text-align: center;
    position: absolute;
    top: 6.666667rem;
    transform: translate(-50%, -50%);
    left: 50%;
    color: #c3c3c3;
}
</style>
<body>
<!--
    制作者：九哥
    页面：客户页面
    时间：2019-03-01
-->





<!----------找客户页面---------->
<div id="companyPage"><!--此ID页面切换用-->
    <div id="companyTitle">
        <b>找客户</b>
        <img src="../images/return.png" id="companyRtn">
    </div>
   <!-- <div id="companyPpt">
        <img src="/uploads/20190227/companyppt.png">
    </div> -->
    <div id="companyDetail">
        <div style="height:10px;"></div>
        <div class="menu">
            <p class="letTitle">推荐</p>
            <div id="companyMore">更多公司</div>
        </div>
        <div class="list"></div>
    </div>
</div>
<!----------找客户页面---------->





<!----------错误提示---------->
<div id="errMsg"></div>
<!----------错误提示---------->
</body>
<script type="text/javascript" src="../js/indexPageChange.js"></script>
<script type="text/javascript" src="../js/index.js"></script>
<script type="text/javascript" src="../js/loading.js"></script>
<script>
    $(function() {
        $.ajax({
        url: '/api/home/customer/cate',
        type:'get',
        dataType:'json',
        contentType: "application/json",
        // async: false,
        success: function (result) {
            if (result.code === 200) {
                var data = result.data;
                console.log(data)
                var div = '';
                for (let i = 0; i < data.length; i++) {
                    if (i === 0) {
                        div += `<div data-id="${data[i].id}" class="comMenu companyPageActive" onclick="comMenu(${data[i].id})">${data[i].name}</div>`
                    } else {
                        if (i > 8) {
                            div += `<div data-id="${data[i].id}" class="comMenu none" onclick="comMenu(${data[i].id})">${data[i].name}</div>`
                        } else {
                            div += `<div data-id="${data[i].id}" class="comMenu" onclick="comMenu(${data[i].id})">${data[i].name}</div>`
                        }
                    }
                    
                    
                }
                list(data[0].id)
                $('.letTitle').after(div)   
            }
        }
    }); 

    $('#companyMore').click(function() {
        var menu = $('.menu');
        console.log(menu)
        menu.find('.comMenu').css('display', 'block');
        $(this).remove();
    })
})

function list(id) {
    $.ajax({
        url: '/api/home/customer',
        type:'get',
        data: {cate: id},
        dataType:'json',
        contentType: "application/json",
        // async: false,
        success: function (result) {
            $('.list').children().remove()
            if (result.code === 200) {
                var data = result.data
                var div = '';
                if (data.length > 0) {
                    for (let i = 0; i < data.length; i++) {
                        div += `<div class="company toComHome" onclick="toComHome(${data[i].id}, ${data[i].uid})" data-id="${data[i].id}" data-uid="${data[i].uid}">
                                    <img src="${data[i].head}">
                                    <p>${data[i].com_name}</p>
                                </div>`
                    }
                    $('.list').append(div)
                } else {
                    var div = '<div class="nullCetner">啊噢，暂时没找到呢</div>'
                    $('.list').append(div)
                }
                
            } else {
                alertMsg(data.msg)
            }
            // var img=new Image();
            // img.src= '';
            // img.onload=function(){
            // }  
        }, err: function(err) {
            alertMsg(err)
        }
    });
}

function comMenu(id) {
    console.log(id)
    var menu = $('.menu');
    var ids = menu.find(`.comMenu[data-id=${id}]`);
    ids.addClass('companyPageActive')
    ids.siblings('.comMenu').removeClass('companyPageActive')
    list(id)
} 

function toComHome(id, uid) {
    var ids = {
        id: id,
        ids: ids
    }

    window.location.href = 'comShow.html?uid=' + uid
}
</script>
</html>